package com.ruoyi.mytool.service.impl;

import com.ruoyi.mytool.service.ImageService;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.springframework.stereotype.Service;

@Service
public class ImageServiceImpl implements ImageService {
    @Override
    public String imageContrastEnhance(String base64) {
        String inputFilePath = "D:\\个人证件\\1.png";
        String outputFilePath = "D:\\个人证件\\2.png";
        System.out.println("1123213");
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat srcImage = Imgcodecs.imread("D:/个人证件/1.png");
        Mat dstImage = new Mat();
        Imgproc.cvtColor(srcImage, dstImage, Imgproc.COLOR_BGR2GRAY,0);
        Imgcodecs.imwrite("D:/个人证件/1.png", dstImage);
        return null;
        // 输入和输出文件路径

//
//        // 读取输入图像
//        BufferedImage inputImage = ImageIO.read(new File(inputFilePath));
//
//        // opencv实现将图片转为灰阶图像
//        Mat mat = Java2DFrameConverter.toMat(inputImage);
//        // 将BufferedImage转换为Mat
//        Mat mat = Java2DFrameConverter.toMat(inputImage);
//
//        // 转换为灰度图像
//        opencv_imgproc.cvtColor(mat, mat, opencv_imgproc.COLOR_BGR2GRAY);
//
//        // 将Mat转换回BufferedImage
//        BufferedImage outputImage = Java2DFrameConverter.toBufferedImage(mat);
//
//        // 保存处理后的图像
//        ImageIO.write(outputImage, "png", new File(outputFilePath));
//
//        System.out.println("图像已成功转换为灰度图像并保存为 " + outputFilePath);
    }
}
